<template>
 <TreeSelect :readOnly="readOnly" :allowClear="allowClear" :ret-attr="retAttr" :multiple="multiple"  v-model="selectVal" :treeData="treeData" :placeholder='placeholder' :strategy="strategy"></TreeSelect>
</template>

<script>
import AppFrame from '../libs/app-frame';
import TreeSelect from '../components/tree-select';
export default {
    name: 'dict-select',
    //props: ['label','value','multiple','placeholder','parentId','retAttr'],
    props:{
        label:{default:''},
        value:{default:''},
        multiple:{default:false},
        placeholder:{default:'请选择'},
        parentId:{default:0},
        partnersId:{default:0},
        retAttr:{default:'value'},
        strategy:{default:'SHOW_ALL'},
        readOnly:{default:false},
        allowClear:{default:true}
    },
     model: {
        prop: 'value',
        event: 'updateVal'
    },
    components:{
        TreeSelect
    },
    data: function() {	
        return {
            selectVal:this.value,
            treeData:[]
        }
    },
 
    created () {
       // if(!this.retAttr) this.retAttr='value';
       this.getData(this.label,this.parentId);
    },

    watch: {
        label:async function(curVal,oldVal){
            if(curVal!=oldVal){
                 await this.getData();
            }
        },
        parentId:async function(curVal,oldVal){
            if(curVal!=oldVal){
                 await this.getData();
            }
        },
        partnersId:async function(curVal,oldVal){
           if(curVal!=oldVal){
                 await this.getData();
            }
        },
        value:function(curVal){
            this.selectVal=curVal;
        },
        selectVal:function(curVal,oldVal){
            this.setValue(curVal);
        }
         
    },
    methods: {
        init:function(){
            if(this.placeholder || this.placeholder==='') this.placeholder="请选择"; 
        },
        getData:async function(){
            let postData={
                label:this.label,
                parentId:this.parentId,
                partnersId:this.partnersId
            }
          let ret = await AppFrame.Http.Post("/manage-api/system/iframe-dict/getdictsTreeData",postData);
         
         if(ret && ret.Result==1){

              this.treeData=ret.Data;
          }
        },
         setValue: function(val) {
            this.$emit("updateVal", val);
        },
    }
}
</script>

<style scoped>

</style>